package thread;

import java.util.concurrent.CountDownLatch;

public class ThreadLocalDemo {
    public static final ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {
        threadLocal.set("123");
        System.out.println("main get -> " + threadLocal.get());
        CountDownLatch latch = new CountDownLatch(1);

        new Thread(() -> {
            System.out.println("thread get -> " + threadLocal.get());
            threadLocal.set("567");
            System.out.println("thread get -> " + threadLocal.get());
            latch.countDown();
        }).start();

        latch.await();
        System.out.println("main get -> " + threadLocal.get());
    }
}
